package com.mindcoord.handbook.controller;

import com.alibaba.fastjson.JSON;
import com.mindcoord.handbook.common.Result;
import com.mindcoord.handbook.pojo.Clazz;
import com.mindcoord.handbook.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping(value = "/clazz", produces = "application/json; charset=utf-8")
public class ClazzController {

    private ClazzService clazzService;

    @Autowired
    public void setClazzService(ClazzService clazzService) {
        this.clazzService = clazzService;
    }

    @GetMapping("/")
    public Object listClazz() {
        Result result = clazzService.listClazzs();
        return JSON.toJSONString(result);
    }

    @GetMapping("/{id}")
    public Object getClazzById(@PathVariable("id") Integer id) {
        Result result = clazzService.getClazzById(id);
        return JSON.toJSONString(result);
    }

    @PostMapping("/put")
    public Object insertClazz(Clazz clazz) {
        Result result = clazzService.insertClazz(clazz);
        return JSON.toJSONString(result);
    }

    @DeleteMapping("/{id}")
    public Object deleteStudentById(@PathVariable("id") Integer id) {
        Result result = clazzService.deleteClazzById(id);
        return JSON.toJSONString(result);
    }

    @PutMapping("/put")
    public Object updateClazz(Clazz clazz) {
        Result result = clazzService.updateClazz(clazz);
        return JSON.toJSONString(result);
    }

}
